package com.example.flutter_sdk_demo.toast

import android.content.Context
import com.hjq.toast.ToastUtils
import io.flutter.plugin.common.BinaryMessenger
import io.flutter.plugin.common.MethodChannel

object ToastProviderPlugin {
    /** Channel名称  **/
    private const val ChannelName = "com.example.flutter_sdk_demo.plugins/toast"

    /**
     * 注册Toast插件
     * @param context 上下文对象
     * @param messenger 数据信息交流对象
     */
    @JvmStatic
    fun register(context: Context, messenger: BinaryMessenger) = MethodChannel(messenger, ChannelName).setMethodCallHandler { methodCall, result ->
        when (methodCall.method) {
            "debugShow" -> ToastUtils.debugShow(methodCall.argument<String>("message"))
            "show" -> ToastUtils.show(methodCall.argument<String>("message"))
        }
        result.success(null) //没有返回值，所以直接返回为null
    }


}